<template>
  <el-card shadow="never">
    <e-table
      ref="eTable"
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :total="total"
    />
  </el-card>
</template>

<script>
import { getReportAuxDrugFeeRank } from '@/api/reports'
export default {
  data() {
    return {
      total: 1,
      loading: false,
      tableData: [],
      columns: [],
      queryParam: {
        pageSize: 10,
        pageNo: 1
      }
    }
  },
  methods: {
    //columns 动态删减，根据form传递过来的数据
    async handleGetList(param = {}) {
      this.loading = true
      this.columns = []
      this.queryParam = Object.assign(this.queryParam, param)

      if (this.queryParam.auxDrugState) {
        this.columns.unshift(
          {
            label: '辅助药名称',
            prop: 'aux_drug_name'
          },
          {
            label: '辅助药代码',
            prop: 'aux_drug_code'
          },
          {
            label: '辅助药金额',
            prop: 'aux_drug_cost'
          }
        )
      }
      if (this.queryParam.doctorState) {
        this.columns.unshift(
          {
            label: '医生名称',
            prop: 'doctor_name'
          },
          // {
          //   label: '医生代码',
          //   prop: 'doctor_code'
          // },
          {
            label: '药物花费',
            prop: 'aux_drug_cost'
          }
        )
      }

      if (this.queryParam.hisDeptState) {
        this.columns.unshift(
          {
            label: '科室名称',
            prop: 'his_dept_name'
          },
          {
            label: '科室代码',
            prop: 'his_dept_code'
          }
        )
      }
      if (this.queryParam.dateState) {
        this.columns.unshift({
          label: '日期',
          prop: 'dt'
        })
      }
      const res = await getReportAuxDrugFeeRank(this.queryParam)
      if (res && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>
